package cn.itlight.mq01;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;
import java.util.zip.DeflaterInputStream;

public class Producer {

    public static void main(String[] args) throws Exception {
        // 创建生产者对象
        DefaultMQProducer producer = new DefaultMQProducer("pet_dog_group");
        // 连接mq
        producer.setNamesrvAddr("127.0.0.1:9876");
        // 启动生产者
        producer.start();
        // 创建消息,发送消息
        Message message = new Message("pet_topic", "pet_tags", "拉布拉多拉的多不多？"
                .getBytes(StandardCharsets.UTF_8));
        SendResult send = producer.send(message);
        // 打印消息发送结果
        System.out.println(send);
        // 关闭生产者
        producer.shutdown();

    }
}
